package view;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.example.administrator.text.R;
import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by liuxiaobin on 2017/4/7
 * 首页的头部VIEW
 */

public class HomeHeadF extends LinearLayout{
    private OnViewClickListener mOnViewClickListener;
    private View mView;
    private Context mContext;
    private String mTvName;

    @Bind(R.id.view_tv_name)         TextView mTextView;
    @Bind(R.id.view_et_input)        EditText mEditText;
    @Bind(R.id.view_homehead_left)   ImageView imageViewLeft;
    @Bind(R.id.view_homehead_right)  ImageView imageViewRight;

    public HomeHeadF(Context context) {
        super(context);
    }

    public HomeHeadF(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
        //parestAttr(attrs);
        init();
    }

    private void init() {
        mView = RelativeLayout.inflate(mContext, R.layout.view_home_head, null);
        addView(mView);
        ButterKnife.bind(this);

        if(mTvName.equals("")){
            mTextView.setVisibility(View.GONE);
            mEditText.setVisibility(VISIBLE);
        }else {
            mTextView.setVisibility(View.VISIBLE);
            mEditText.setVisibility(GONE);
            mTextView.setText(mTvName);
        }
        imageViewLeft.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                        if(mOnViewClickListener !=null){
                            mOnViewClickListener.onItemClick("Left");
                        }
                  }
        });

        imageViewRight.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mOnViewClickListener !=null){
                    mOnViewClickListener.onItemClick("Right");
                }
            }
        });

        mEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });


    }


    /**
     * view 事件的回调
     */
    public interface OnViewClickListener {
        void onItemClick(String type);
    }

    /**
     * 获取view 的事件
     */
    public void setOnViewClickListener(OnViewClickListener listener) {
        this.mOnViewClickListener = listener;
    }
}
